package com.wjh.anyview.controller;

import com.wjh.anyview.entity.bo.courseServiceBo.InstitutionGradeBo;
import com.wjh.anyview.entity.dto.CommonResult;
import com.wjh.anyview.entity.po.ClazzCourse;
import com.wjh.anyview.entity.po.Course;
import com.wjh.anyview.entity.vo.courseControllerVo.CourseInfoVo;
import com.wjh.anyview.service.ClazzService;
import com.wjh.anyview.service.CourseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wjh
 * @date 2021/10/9 18:42
 * @Package com.wjh.anyview.controller
 */
@RestController
@RequestMapping("/api/course")
public class CourseController {
    @Resource
    private CourseService courseService;

    @Resource
    private ClazzService clazzService;

    @PostMapping("/saveCourse")
    @PreAuthorize("hasAuthority('/saveCourse')")
    public CommonResult<?> saveCourse(@RequestBody Course course) {
        return courseService.saveCourse(course);
    }

    @PostMapping("/updateCourseById")
    @PreAuthorize("hasAuthority('/updateCourseById')")
    public CommonResult<?> updateCourseById(@RequestBody Course course) {
        return courseService.updateCourseById(course);
    }

    @PostMapping("/arrangeCourse")
    @PreAuthorize("hasAuthority('/arrangeCourse')")
    public CommonResult<?> arrangeCourse(@RequestBody ClazzCourse clazzCourse) {
        return clazzService.arrangeCourse(clazzCourse);
    }

    @PostMapping("/deleteCourseById")
    @PreAuthorize("hasAuthority('/deleteCourseById')")
    public CommonResult<?> deleteCourseById(@RequestParam("courseId") Long courseId) {
        return courseService.deleteCourseById(courseId);
    }

    @PostMapping("/listCourseByInstitutionGrade")
    @PreAuthorize("hasAuthority('/listCourseByInstitutionGrade')")
    public CommonResult<List<CourseInfoVo>> listCourseByInstitutionGrade(@RequestBody InstitutionGradeBo institutionGradeBo) {
        return courseService.listCourseByInstitutionGrade(institutionGradeBo);
    }

}
